<template>
  <view class="outfit-page">
    <!-- 顶部分类Tab -->
    <view class="top-wrapper">
      <scroll-view class="category-tabs" scroll-x scroll-with-animation show-scrollbar="{{false}}">
        <view class="tabs-wrapper">
          <view 
            v-for="(cat, i) in categories" 
            :key="i"
            class="tab-item"
            :class="{ active: currentCategory === cat.value }"
            @click="switchCategory(cat.value)"
          >
            <text class="tab-emoji">{{ cat.emoji }}</text>
            <text class="tab-text">{{ cat.label }}</text>
          </view>
        </view>
      </scroll-view>
    </view>

    <!-- 衣服列表 -->
    <view class="outfit-list" v-if="filteredOutfits.length > 0">
      <view 
        v-for="(item, i) in filteredOutfits" 
        :key="i"
        class="outfit-card"
        @click="viewDetail(item)"
      >
        <!-- 收藏按钮 -->
        <view class="favorite-btn" @click.stop="toggleFavorite(item)">
          <text class="heart-icon">{{ item.favorite ? '❤️' : '🤍' }}</text>
        </view>
        
        <!-- 图片区域 -->
        <view class="image-wrapper">
          <image v-if="item.image" :src="item.image" class="outfit-image" mode="aspectFill" />
          <view v-else class="placeholder-image">
            <text class="placeholder-icon">👗</text>
          </view>
          
          <!-- 图片上的标签 -->
          <view class="image-tags">
            <text v-if="item.season" class="season-badge">{{ item.season }}</text>
          </view>
        </view>
        
        <!-- 信息卡片 -->
        <view class="info-card">
          <view class="brand-row">
            <text class="brand-name">{{ item.brand || '未知品牌' }}</text>
            <view class="wear-badge">
              <text class="wear-text">穿了{{ item.wearCount || 0 }}次</text>
            </view>
          </view>
          
          <view class="price-row">
            <view class="price-info">
              <text class="price-label">购入价</text>
              <text class="price-value">¥{{ item.price || 0 }}</text>
            </view>
            <view class="cost-info">
              <text class="cost-label">单次成本</text>
              <text class="cost-value">¥{{ item.costPerWear || 0 }}</text>
            </view>
          </view>
        </view>
      </view>
    </view>

    <!-- 空状态 -->
    <view v-else class="empty-state">
      <view class="empty-content">
        <text class="empty-icon">✨</text>
        <text class="empty-title">还没有衣服哦~</text>
        <text class="empty-desc">快来添加你的第一件单品吧</text>
        <view class="add-button" @click="addOutfit">
          <text class="add-icon">+</text>
          <text class="add-text">添加单品</text>
        </view>
      </view>
    </view>

    <!-- 底部悬浮按钮 -->
    <view v-if="filteredOutfits.length > 0" class="fab" @click="addOutfit">
      <text class="fab-icon">+</text>
      <view class="fab-ripple"></view>
    </view>
  </view>
</template>

<script setup>
import { ref, computed } from 'vue'
import { onShow } from '@dcloudio/uni-app'

// 分类列表（添加可爱的emoji）
const categories = [
  { label: '全部', value: 'all', emoji: '✨' },
  { label: '上装', value: 'top', emoji: '👚' },
  { label: '下装', value: 'bottom', emoji: '👖' },
  { label: '连体', value: 'onepiece', emoji: '👗' },
  { label: '外套', value: 'outer', emoji: '🧥' },
  { label: '鞋子', value: 'shoes', emoji: '👠' }
]

const currentCategory = ref('all')
const outfits = ref([])

// 过滤后的衣服列表
const filteredOutfits = computed(() => {
  if (currentCategory.value === 'all') {
    return outfits.value
  }
  return outfits.value.filter(item => item.category === currentCategory.value)
})

// 切换分类
function switchCategory(value) {
  currentCategory.value = value
}

// 添加衣服
function addOutfit() {
  uni.navigateTo({
    url: '/pages/outfit/add'
  })
}

// 查看详情
function viewDetail(item) {
  uni.navigateTo({
    url: '/pages/outfit/detail?id=' + item.id
  })
}

// 切换收藏状态
function toggleFavorite(item) {
  item.favorite = !item.favorite
  // 保存到本地存储
  uni.setStorageSync('outfits', outfits.value)
  
  // 触觉反馈
  uni.vibrateShort({ type: 'light' })
}

// 页面显示时加载数据
onShow(() => {
  loadOutfits()
})

function loadOutfits() {
  const data = uni.getStorageSync('outfits') || []
  outfits.value = data
}
</script>

<style lang="scss" scoped>
.outfit-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #FFF5F7 0%, #F3E8FF 100%);
  padding-bottom: calc(140rpx + env(safe-area-inset-bottom)); // 为悬浮TabBar留出空间
}

.top-wrapper {
  position: sticky;
  top: 0;
  z-index: 99;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20rpx);
  box-shadow: 0 4rpx 20rpx rgba(255, 182, 193, 0.1);
}

.category-tabs {
  white-space: nowrap;
}

.tabs-wrapper {
  display: inline-flex;
  padding: 20rpx 24rpx;
  gap: 12rpx;
}

.tab-item {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16rpx 24rpx;
  border-radius: 28rpx;
  background: transparent;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  
  .tab-emoji {
    font-size: 36rpx;
    margin-bottom: 6rpx;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .tab-text {
    font-size: 24rpx;
    color: #8B7B8B;
    font-weight: 500;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  &.active {
    background: linear-gradient(135deg, #FFE5EC 0%, #F3E8FF 100%);
    box-shadow: 0 4rpx 16rpx rgba(255, 182, 193, 0.25);
    
    .tab-emoji {
      transform: scale(1.1);
    }
    
    .tab-text {
      color: #D87093;
      font-weight: 600;
    }
  }
  
  &:active {
    transform: scale(0.95);
  }
}

.outfit-list {
  padding: 24rpx;
  display: flex;
  flex-direction: column;
  gap: 24rpx;
}

.outfit-card {
  background: #fff;
  border-radius: 24rpx;
  overflow: hidden;
  box-shadow: 0 8rpx 32rpx rgba(255, 182, 193, 0.15);
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  
  &:active {
    transform: scale(0.98);
    box-shadow: 0 4rpx 16rpx rgba(255, 182, 193, 0.2);
  }
}

.favorite-btn {
  position: absolute;
  top: 20rpx;
  right: 20rpx;
  width: 64rpx;
  height: 64rpx;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10rpx);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
  z-index: 10;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  
  .heart-icon {
    font-size: 36rpx;
    line-height: 1;
  }
  
  &:active {
    transform: scale(1.2);
  }
}

.image-wrapper {
  width: 100%;
  height: 400rpx;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #FFE5EC 0%, #F3E8FF 100%);
}

.outfit-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.placeholder-image {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  
  .placeholder-icon {
    font-size: 120rpx;
    opacity: 0.5;
  }
}

.image-tags {
  position: absolute;
  bottom: 16rpx;
  left: 16rpx;
  display: flex;
  gap: 12rpx;
}

.season-badge {
  padding: 8rpx 20rpx;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10rpx);
  border-radius: 20rpx;
  font-size: 22rpx;
  color: #D87093;
  font-weight: 600;
  box-shadow: 0 4rpx 12rpx rgba(216, 112, 147, 0.2);
}

.info-card {
  padding: 24rpx;
}

.brand-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20rpx;
}

.brand-name {
  font-size: 32rpx;
  font-weight: 600;
  color: #333;
  background: linear-gradient(135deg, #D87093 0%, #9370DB 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.wear-badge {
  padding: 8rpx 16rpx;
  background: linear-gradient(135deg, #FFE5EC 0%, #F3E8FF 100%);
  border-radius: 20rpx;
  
  .wear-text {
    font-size: 22rpx;
    color: #8B7B8B;
    font-weight: 500;
  }
}

.price-row {
  display: flex;
  gap: 32rpx;
}

.price-info,
.cost-info {
  flex: 1;
  padding: 16rpx;
  background: linear-gradient(135deg, #FFF5F7 0%, #F8F9FF 100%);
  border-radius: 16rpx;
  display: flex;
  flex-direction: column;
  gap: 8rpx;
}

.price-label,
.cost-label {
  font-size: 22rpx;
  color: #8B7B8B;
}

.price-value,
.cost-value {
  font-size: 28rpx;
  font-weight: 700;
  color: #D87093;
}

.empty-state {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60rpx;
}

.empty-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.empty-icon {
  font-size: 160rpx;
  margin-bottom: 32rpx;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-20rpx);
  }
}

.empty-title {
  font-size: 32rpx;
  color: #8B7B8B;
  font-weight: 600;
  margin-bottom: 16rpx;
}

.empty-desc {
  font-size: 26rpx;
  color: #B8A8B8;
  margin-bottom: 48rpx;
  line-height: 1.6;
}

.add-button {
  display: flex;
  align-items: center;
  gap: 12rpx;
  padding: 24rpx 56rpx;
  background: linear-gradient(135deg, #FFB6C1 0%, #DDA0DD 100%);
  color: #fff;
  border-radius: 48rpx;
  font-size: 30rpx;
  font-weight: 600;
  box-shadow: 0 8rpx 24rpx rgba(255, 182, 193, 0.4);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  
  .add-icon {
    font-size: 36rpx;
    font-weight: 300;
  }
  
  .add-text {
    line-height: 1;
  }
  
  &:active {
    transform: scale(0.95);
    box-shadow: 0 4rpx 16rpx rgba(255, 182, 193, 0.3);
  }
}

.fab {
  position: fixed;
  right: 40rpx;
  bottom: 140rpx;
  width: 112rpx;
  height: 112rpx;
  border-radius: 50%;
  background: linear-gradient(135deg, #FFB6C1 0%, #DDA0DD 100%);
  box-shadow: 0 8rpx 32rpx rgba(255, 182, 193, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  
  .fab-icon {
    font-size: 56rpx;
    color: #fff;
    font-weight: 300;
    line-height: 1;
  }
  
  .fab-ripple {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3rpx solid rgba(255, 182, 193, 0.6);
    animation: ripple 2s infinite;
  }
  
  &:active {
    transform: scale(0.9);
  }
}

@keyframes ripple {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}
</style>

